$(function () {
    var pathName=window.document.location.pathname;
    var projectName=pathName.substring(0,pathName.substr(1).indexOf('/')+1);
    //关闭对话框
    $("#Cancel").click(function () {
        Config.close();
    });
    //提交config修改根路径
    $("#editRootPathEnsure").click(function () {
        Config.editRootPathEnsureSubmit();
    });
    //提交config修改根路径
    $("#editHtmlExePathEnsure").click(function () {
        Config.editHtmlExePathSubmit();
    });
});

var Config = {
    reqData:{},
}

//关闭此对话框
Config.close = function () {
    parent.layer.close(window.parent.Config.layerIndex);
}
//提交编辑根目录
Config.editRootPathEnsureSubmit = function () {
    this.clearData();
    this.collectData();
    var pathName=window.document.location.pathname;
    var projectName=pathName.substring(0,pathName.substr(1).indexOf('/')+1);
    $.ajax({
        type:'post',
        contentType:'application/json',
        dataType:'json',
        url:projectName+'/config/editFileRootPath',
        data:JSON.stringify(this.reqData),
        success:function (data) {
            if(data.success){
                Config.close();
                Feng.success(data.msg||"修改成功!");
            } else {
                Feng.error(data.msg||"修改失败!");
            }
        }
    })
}
//提交默认浏览器
Config.editHtmlExePathSubmit = function () {
    this.clearData();
    this.collectData();
    var pathName=window.document.location.pathname;
    var projectName=pathName.substring(0,pathName.substr(1).indexOf('/')+1);
    $.ajax({
        type:'post',
        contentType:'application/json',
        dataType:'json',
        url:projectName+'/config/editHtmlExePath',
        data:JSON.stringify(this.reqData),
        success:function (data) {
            if(data.success){
                Config.close();
                Feng.success(data.msg||"修改成功!");
            } else {
                Feng.error(data.msg||"修改失败!");
            }
        }
    })
}
//清除数据
Config.clearData = function () {
    this.reqData = {};
}
//收集数据
Config.collectData = function () {
    this.set('configValue');
}
//收集数据--按照id,第一个参数是input的id，第二个若没有第一个参数必须是实体的属性名，若有则为实体的属性名，即input的id可以随意起名
Config.set = function (key,modelKey,value) {
    if(typeof value == "undefined"){
        if(typeof $("#" + key).val() =="undefined"){
            var str="";
            var ids="";
            $("input[name='"+key+"']:checkbox").each(function(){
                if(true == $(this).is(':checked')){
                    str+=$(this).val()+",";
                }
            });
            if(str){
                if(str.substr(str.length-1)== ','){
                    ids = str.substr(0,str.length-1);
                }
            }else{
                $("input[name='"+key+"']:radio").each(function(){
                    if(true == $(this).is(':checked')){
                        ids=$(this).val()
                    }
                });
            }
            if(typeof modelKey == "undefined"){
                this.reqData[key] = ids;
            }else {
                this.reqData[modelKey] = ids;
            }
        }else{
            if(typeof modelKey == "undefined"){
                this.reqData[key]= $("#" + key).val();
            }else {
                this.reqData[modelKey] = $("#" + key).val();
            }
        }
    }
    return this;
}
